
<?php


class Connect{

	private $dbHost = 'localhost';

	private $dbUser = 'root';

	private $dbPass = 'vertrigo'; 

	private $dbName = 'datn1415'; 

	//-------------------------//

	private $conn; // connection

	private $rs; // resultset

	private $str_query; // sql query

	private $rows_num_effect;

	// connect to database

	public function __construct() {

		$this->conn= new mysqli($this->dbHost,$this->dbUser, $this->dbPass,$this->dbName);	

		if ($this->conn->connect_error) {

			trigger_error('Database connection failed: '  . $this->conn->connect_error, E_USER_ERROR);

			exit();
		}
	}
    
    // update, insert, delete 
	public function Query($sql)
	{
		$this->conn->query("SET NAMES 'utf8'");

		$this->str_query=$sql;

		$this->rs=$this->conn->query($sql);

		$this->rows_num_effect=$this->rs->num_rows;

		if (!$this->rs){
			 echo "Error: ".var_dump($sql);
		}
			
	}

	// list 
	public function Fetch(){	
		
		if ($this->rs){
			$kq=$this->rs->fetch_assoc();			
			//print_r($kq);			
		} 	

		return $kq;			
	}

	public function getRS(){
		return $this->rs;
	}

	public function getNumRows(){
		return $this->rows_num_effect;
	}


	public function close(){					
		$this->conn->close();
		
	}

}

?>